﻿using KPI.Data;
using KPI.Entity;
using KPI.UIBase;
using ScheduleManager.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TYBase;

namespace ScheduleManager.Helpers
{
    public class UIDataHelper
    {
        static IntStringData DataAsShiftModel(IEnumerable<IntStringData> listShift, int key)
        {
            IntStringData data = listShift.FirstOrDefault(x => x.Key == key);
            if (data == null)
            {
                data = new IntStringData { Key = key, Value = AppDictData.GetLabel(EnumDictType.shift, key) };
            }
            return data;

        }

        public static ScheduleModel DataAsUI(ScheduleVO item, IEnumerable<IntStringData> listShift)
        {
            ScheduleModel model = new ScheduleModel(item)
            {
                UserName = item.user_name,

            };
            if (item.schedule == null)
            {
                item.schedule = new Tbl_Schedule();
            }
            model.Shift1_key = DataAsShiftModel(listShift, item.schedule.shift1_key.NullAs());
            model.Shift2_key = DataAsShiftModel(listShift, item.schedule.shift2_key.NullAs());
            model.Shift3_key = DataAsShiftModel(listShift, item.schedule.shift3_key.NullAs());
            model.Shift4_key = DataAsShiftModel(listShift, item.schedule.shift4_key.NullAs());
            model.Shift5_key = DataAsShiftModel(listShift, item.schedule.shift5_key.NullAs());
            model.Shift6_key = DataAsShiftModel(listShift, item.schedule.shift6_key.NullAs());
            model.Shift7_key = DataAsShiftModel(listShift, item.schedule.shift7_key.NullAs());

            return model;
        }

        //public static ScheduleModel DataAsUI(ScheduleVO item, List<IntStringData> listShift)
        //{
        //    ScheduleModel model = new ScheduleModel(item)
        //    {
        //        UserName = item.user_name,

        //    };
        //    model.Shift1_key = DataAsShiftModel(listShift, item.shift1_key);
        //    model.Shift2_key = DataAsShiftModel(listShift, item.shift2_key);
        //    model.Shift3_key = DataAsShiftModel(listShift, item.shift3_key);
        //    model.Shift4_key = DataAsShiftModel(listShift, item.shift4_key);
        //    model.Shift5_key = DataAsShiftModel(listShift, item.shift5_key);
        //    model.Shift6_key = DataAsShiftModel(listShift, item.shift6_key);
        //    model.Shift7_key = DataAsShiftModel(listShift, item.shift7_key);

        //    return model;
        //}
    }
}
